1. Linux commands
| Command | Description |
|---|---|
whoami |
Displays the current user's username. |
id |
Prints the real and effective user and group IDs. |
hostname |
Displays the system's hostname (TCP/IP hostname). |
uptime |
Shows how long the system has been running since the last boot. |
date |
Displays the current date and time. |
cal |
Displays a calendar. If no arguments are given, it shows the current month. |
clear |
Clears the terminal screen. |
echo 'text' |
Prints the specified text to the terminal. The text should be enclosed in single quotes. |
history |
Displays the user's command history. |
! + command # |
Re-executes a command from the history by its number. |
touch filename |
Creates a new empty file, or updates the modification and access times of an existing file. |
cat filename |
Displays the contents of a file. |
0< filename |
Redirects the contents of the file to standard input (stdin). Often used with commands like cat. |
1> filename |
Redirects the standard output (stdout) of a command to a file (overwrites the file if it exists). |
2> filename |
Redirects standard error (stderr) messages from a command to a file. |
Tab |
Autocompletes commands and filenames. Pressing twice shows all matching options. |
man command |
Displays the manual page for a specific command, providing detailed information on its purpose, syntax, options, and usage examples. |
pwd |
Prints the present working directory (the directory you are currently in). Useful for understanding your location in the file system. |
ls |
Lists files and directories in the current directory. The -l option provides a detailed listing with file permissions, ownership, size, and modification time. |
cd directory |
Changes the current directory to the specified directory. |
Explanation of Redirection Operators:
- **
<: Input redirection. Takes input from the specified file instead of the keyboard. - **`>``: Output redirection. Sends the output of a command to the specified file.
- **
>>: Appends the output of a command to the specified file.
Note: This table is not exhaustive but includes many essential commands for navigating the Linux command line. You can use the man command or online resources to learn more about these and other commands.
other necessary commands
| Command | Usage | Description | Example |
|---|---|---|---|
pwd |
pwd |
Displays the current working directory. | If in /home/user, output is /home/user. |
ls |
ls [options] [directory] |
Lists files and directories in the current directory. Options: -l for details, -a for hidden files. |
ls -l (detailed list), ls -a (all files). |
cd |
cd [directory] |
Changes the current directory to the specified directory. | cd /home/user/Documents (moves to Documents). |
touch |
touch [filename] |
Creates a new empty file or updates the timestamp of an existing file. | touch file.txt (creates or updates file.txt). |
mkdir |
mkdir [directory name] |
Creates a new directory. | mkdir new_folder (creates a directory named new_folder). |
rm |
rm [options] [file/directory] |
Deletes a file or directory (-r for recursive deletion of a directory). |
rm file.txt (deletes file.txt), rm -r folder (deletes a folder). |
cp |
cp [source] [destination] |
Copies files or directories from one location to another. | cp file1.txt file2.txt (copies file1.txt to file2.txt). |
mv |
mv [source] [destination] |
Moves or renames files or directories. | mv old_name.txt new_name.txt (renames old_name.txt). |
cat |
cat [filename] |
Displays the content of a file. | cat file.txt (shows the content of file.txt). |
nano |
nano [filename] |
Opens a simple text editor to edit files. | nano file.txt (edits file.txt). |
chmod |
chmod [permissions] [file] |
Changes the file permissions. Permissions can be numeric (e.g., 755) or symbolic (e.g., u+x). |
chmod 755 script.sh (sets execute permission). |
chown |
chown [owner]:[group] [file] |
Changes the owner and group of a file or directory. | chown user:group file.txt (changes ownership). |
grep |
grep [pattern] [file] |
Searches for a pattern (string) in a file or output. | grep 'text' file.txt (finds 'text' in file.txt). |
find |
find [path] [options] |
Searches for files and directories. Options like -name can specify the search criteria. |
find /home -name "*.txt" (finds all .txt files in /home). |
man |
man [command] |
Displays the manual or help for a specific command. | man ls (shows the manual for ls). |
echo |
echo [text] |
Displays a line of text. Can also be used to write text to files. | echo "Hello World" (prints "Hello World"). |
df |
df [options] |
Shows disk space usage of file systems. Use -h for human-readable format. |
df -h (shows disk usage in GB/MB). |
du |
du [options] [directory] |
Shows disk usage of files and directories. Use -h for human-readable format. |
du -h folder (shows size of folder). |
ps |
ps [options] |
Displays a snapshot of currently running processes. | ps aux (shows all running processes). |
top |
top |
Displays real-time system information, including running processes and system resources. | top (opens the system monitor). |
kill |
kill [PID] |
Terminates a process using its process ID (PID). | kill 1234 (terminates process with PID 1234). |